package com.nami.logic.bo.send;

import com.nami.basic.packet.Packet;
import org.dromara.common.core.utils.IdentityUtil;
import lombok.Data;
import lombok.ToString;

import java.io.Serializable;

/**
 * qos中使用
 * 描述：
 *
 * @Author: lbc
 * @Date: 2023-08-18 8:23
 * @email: 594599620@qq.com
 * @Description: keep coding
 */
@ToString
@Data
public class PacketTransBO implements Serializable {

    /**
     * 消息的id
     */
    private String messageId;
    /**
     * 协议包
     */
    private Packet packet;

    /**
     * appNo
     */
    private String appKey;
    /**
     * 客户端
     */
    private String identityNo;

    /**
     * 此处到dubbo 属于配置下发模式
     */
    private String mqTags;

    private String downMsgMode;

    /**
     * dubbo ip
     */
    private String dubboIp;

    /**
     * dubbo port
     */
    private Integer dubboPort;

    /**
     * 群消息，得finger不同
     */
    private boolean ifGroupMsg;

    private boolean isQos;

    private transient int retryCount = 0;


    public void increaseRetryCount() {
        this.retryCount += 1;
    }

    /**
     * 获取重试机制中的 消息指纹
     *
     * @return
     */
    public String getFingerprint() {
        if (ifGroupMsg) {
            return this.messageId + IdentityUtil.getUserId(this.getIdentityNo());
        }
        return this.messageId + "";
    }

    @Override
    public Object clone() {
        PacketTransBO cloneP = new PacketTransBO();
        cloneP.setPacket(this.packet);
        cloneP.setMessageId(this.messageId);
        cloneP.setQos(this.isQos);

        cloneP.setIdentityNo(this.identityNo);
        cloneP.setAppKey(this.appKey);
        cloneP.setIfGroupMsg(this.ifGroupMsg);
        cloneP.setRetryCount(this.retryCount);

        cloneP.setMqTags(this.mqTags);
        cloneP.setDubboIp(this.dubboIp);
        cloneP.setDubboPort(this.dubboPort);
        return cloneP;
    }


}
